<?php
class Install_Service_Common extends My_Service{
	function getAdmMenu(){
		$config = My_Config::getInstance()->getConfig("init", 1, 1, "install");
		return isset($config['adminUrl']) ? $config['adminUrl']:"";
	}
	
	function checkDbConn($host,$port,$user,$pwd,$dbName){
		$link=@mysql_connect($host.':'.$port,$user,$pwd);
		if(!$link){
			return '数据库连接失败，请检查连接信息是否正确！';
		}
		$status=@mysql_select_db($dbName,$link);
		if(!$status){
			return '数据库连接成功，请先建立数据库！';
		}
		return true;
	}
	
	function install($host,$port,$user,$pwd,$dbName){
		$data['master']['host'] = $host;
		$data['master']['port'] = $port;
		$data['master']['dbname'] = $dbName;
		$data['master']['username'] = $user;
		$data['master']['password'] = $pwd;
		$data['master']['charset'] = 'utf8';
		
		$data['slave']['host'] = $host;
		$data['slave']['port'] = $port;
		$data['slave']['dbname'] = $dbName;
		$data['slave']['username'] = $user;
		$data['slave']['password'] = $pwd;
		$data['slave']['charset'] = 'utf8';
		
		My_Config::getInstance()->save($data,"db",0,'',1);
		$obj = new Home_Service_Common();
		$obj->install("install");
		$path = ROOT_DIR."/data/install.lock";
		touch($path);
	}
	
}